﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FiFaChamps.logic;

namespace FiFaChamps.View
{
    public partial class MainForm : Form
    {
        Controller cc = new Controller();

        public MainForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            Player newP = new Player();
            newP.name = textBoxName.Text.ToString();
            newP.surname = textBoxSurname.Text.ToString(); 
            newP.email = textBoxEmail.Text.ToString(); 
            newP.phone = textBoxPhone.Text.ToString(); 
            newP.nickname = textBoxNickName.Text.ToString();
            bool c = checkBoxOnlinePlayer.Checked;
            bool? oPlayer =  c == true ? true : false; 
            newP.onlineplayer = oPlayer;
            int? fteam = Int32.Parse("1"/*textBoxFirstTeam.Text.ToString()*/);
            newP.firstTeam = fteam;
            int? sTeam = Int32.Parse("2");
            newP.secondTeam = sTeam;
            newP.playerPicture = "still to sort";    
            
           
           info( cc.createPlayer(newP.name, newP.surname, newP.email, newP.phone, newP.nickname, newP.onlineplayer, newP.firstTeam, newP.secondTeam, newP.playerPicture));
        }

        public void info(string msg)
        {
            if (msg.Length > 40)
                MessageBox.Show(msg);
            else
                toolStripStatusLabel1.Text = msg;
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            var items = cc.allPlayers();
            foreach (var p in items)
            {
                listBox1.Items.Add(p.name);
            }
           
        }

        private void btnLoadPlayers_Click(object sender, EventArgs e)
        {
            listBox1_SelectedIndexChanged(sender, e);
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            var db = Datahandle.DataManager.FifaDB();

            db.FCT_Teams.Count();
        }

        private void btnCreatePlayer_Click(object sender, EventArgs e)
        {

        }
    }
}
